﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LCA.Utils;

public partial class Admin_LCAFlow_UpdateFlow : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Guid? flowId = GetFlowId();
        SetFlowId(flowId);

        if (!IsPostBack)
        {
            RefreshComponents();
        }
    }

    private void RefreshComponents()
    {
        ctlFlowEditor.RefreshComponents();
    }

    private void SetFlowId(Guid? flowId)
    {
        ViewState["FlowId"] = flowId;
        ctlFlowEditor.FlowId = flowId;

    }
    private Guid? GetFlowId()
    {
        if (ViewState["FlowId"] != null)
        {
            return (Guid?)ViewState["FlowId"];
        }
        else
        {
            return StringHelper.ParseGuid(Request.Params["flowId"]);
        }
    }


    protected void ctlFlowEditor_DataSaved(object sender, EventArgs e)
    {
        //SetFlowId(ctlFlowEditor.FlowId);
        //ctlFlowEditor.RefreshComponents();
        Guid id = ctlFlowEditor.FlowId.Value;
        PageHelper.AdminPageRedirect(Page, "UpdateFlow.aspx?flowId=" + id);
    }

    protected void ctlFlowEditor_Cancelled(object sender, EventArgs e)
    {
        PageHelper.AdminPageRedirect(Page, "ManageFlows.aspx");
    }
}